﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" Inherits="BoatList" Codebehind="BoatList.aspx.cs" %>

<%@ Register TagPrefix="avg" Namespace="Avg.Controls" Assembly="SmartPager" %>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <div style="margin: 5px">
        <table id="condition">
            <tr>
                <td>
                    <h1 style="text-indent: 10px">
                        Search Boat</h1>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="label">
                        Boat#:</div>
                    <div class="field">
                        <asp:TextBox ID="txtBoatID" runat="server"></asp:TextBox></div>
                </td>
                <td>
                    <div class="label">
                        Boat name:</div>
                    <div class="field">
                        <asp:TextBox ID="txtBoatName" runat="server"></asp:TextBox></div>
                </td>
                <td>
                    <asp:LinkButton CssClass="button" ID="btnFind" runat="server" ToolTip="Find Button"
                        OnClick="btnFind_Click">
                        <span>Search</span>
                    </asp:LinkButton>
                </td>
            </tr>
        </table>
        <div>
            <asp:GridView ID="grv" runat="server" CssClass="grid" AllowSorting="true" AutoGenerateColumns="false"
                DataKeyField="BoatID">
                <Columns>
                    <asp:TemplateField HeaderText="" SortExpression="Name" HeaderStyle-Width="20" HeaderStyle-HorizontalAlign="Center">
                        <ItemTemplate>
                            <%#Container.DataItemIndex+1 %>
                        </ItemTemplate>
                        <HeaderStyle HorizontalAlign="Center" Height="20px"></HeaderStyle>
                        <ItemStyle HorizontalAlign="Center" Height="20px" />
                    </asp:TemplateField>
                    <asp:BoundField HeaderText="Boat#" DataField="BoatID"></asp:BoundField>
                    <asp:BoundField HeaderText="Boat name" DataField="BoatName"></asp:BoundField>
                    <asp:BoundField HeaderText="Num of cabins" DataField="NumOfCabins"></asp:BoundField>
                    <asp:BoundField HeaderText="Num of floors" DataField="NumOfFloors"></asp:BoundField>
                    <asp:CheckBoxField HeaderText="Active" DataField="Active"></asp:CheckBoxField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <a href="/Pages/Boats/BoatItem.aspx" id="btnNew">Add</a>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <a href="/Pages/Boats/BoatItem.aspx?BoatId=<%#Eval("BoatID") %>" class="btnEdit">Edit</a>
                            |&nbsp;<a boatid="<%#Eval("BoatID") %>" class="btnDelete">Delete</a><br />
                            <a href='/Pages/Boats/CabinItem.aspx?BoatId=<%#Eval("BoatID") %>' style="color: #555;
                                margin-left: 3px">Add</a> |&nbsp;<a href='/Pages/Boats/CabinList.aspx?BoatId=<%#Eval("BoatID") %>'
                                    style="color: #555">List</a>&nbsp;Cabin </ul>
                        </ItemTemplate>
                        <HeaderStyle Width="100"></HeaderStyle>
                    </asp:TemplateField>
                </Columns>
                <HeaderStyle CssClass="gridheader" />
                <RowStyle CssClass="gridrow" />
                <AlternatingRowStyle CssClass="evenRow" />
            </asp:GridView>
            <avg:SmartPager ID="smartPager" runat="server" Visible="false" NavigatePreviousText="« Previous"
                NavigateNextText="Next »">
            </avg:SmartPager>
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            $('#btnNew').button();

            $('.btnDelete').click(function () {
                var btnDelete = $(this);
                var result = confirm("Are you sure you want to delete this record?");
                if (result) {
                    var boatID = $(this).attr("boatid");

                    var params = "{BoatID:'" + boatID + "'}";
                    $.ajax({
                        type: "POST",
                        url: "/Update.asmx/DeleteBoat",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: params,
                        success: function (data) {
                            if (data.d) {
                                // Select provider
                                btnDelete.closest("tr").remove();
                                return false;
                            }
                            else {
                                alert("Delete failed.");
                            }
                        },
                        error: function () {
                            alert("error");
                            return false;
                        }
                    });
                }
            });
        });
    </script>

</asp:Content>
